<?php
	include('../config.ini.php');
	function utf8_to_tis620($string)
	{
		$str = $string;
		$res = "";
		for ($i = 0; $i < strlen($str); $i++) {
		  if (ord($str[$i]) == 224) {
			$unicode = ord($str[$i+2]) & 0x3F;
			$unicode |= (ord($str[$i+1]) & 0x3F) << 6;
			$unicode |= (ord($str[$i]) & 0x0F) << 12;
			$res .= chr($unicode-0x0E00+0xA0);
			$i += 2;
		  } else {
			$res .= $str[$i];
		  }
		}
		return $res;
	}
	
	$name = ($_POST['name']); 
	$email = $_POST['email']; 
	$tel = $_POST['tel'];
	$msg = ($_POST['msg']); 
	
	$to      = CONTACT_EMAIL;
	
	$subject = 'Pathom Furniture : Message from contact.';
	$message = '<strong>ชื่อ - นามสกุล : </strong>'.$name;
	$message .= '<br /><strong>โทรศัพท์ : </strong>'.$tel;
	$message .= '<br /><strong>อีเมล์. : </strong>'.$email;
	$message .= '<br /><strong>ข้อความ : </strong>'.$msg;
	
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
	$headers .= "From: $email" . "\r\n" .
		"Reply-To: $email" . "\r\n" .
		'X-Mailer: PHP/' . phpversion();
	
	if(@mail($to, $subject, $message, $headers))
	{
		echo 'success';
	}
	else
	{
		echo 'Can\'t sent message, please try again later.';
	}
?>